import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hongsheng/pages/user/SPClassRechargeDiamondPage.dart';
import 'package:hongsheng/utils/SPClassCommonMethods.dart';
import 'package:hongsheng/utils/SPClassNavigatorUtils.dart';
import 'package:hongsheng/pages/user/SPClassNewUserWalFarePage.dart';
import 'package:hongsheng/utils/SPClassImageUtil.dart';
import 'package:hongsheng/utils/colors.dart';

class SPClassNewRegisterDialog extends StatefulWidget{
  List ?list=[];
  VoidCallback ?callback;

  SPClassNewRegisterDialog({this.callback,this.list});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return SPClassNewRegisterDialogState();
  }

}

class SPClassNewRegisterDialogState extends State<SPClassNewRegisterDialog>{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return WillPopScope(
      child:Dialog(
        elevation: 0,
        backgroundColor: Colors.transparent,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(top: height(25),bottom:  height(15)),
              width: width(288),

              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  // SPClassEncryptImage.asset(
                  //   SPClassImageUtil.spFunGetImagePath("ic_register_title"),
                  //   width: height(194),
                  // ),
                  // SizedBox(height:height(3) ,),
                  //
                  // Stack(
                  //   alignment: Alignment.topCenter,
                  //   children: <Widget>[
                  //     Container(
                  //       padding: EdgeInsets.only(top: height(10)),
                  //       child: SPClassEncryptImage.asset(
                  //         SPClassImageUtil.spFunGetImagePath("bg_new_user_diamond"),
                  //         width: height(304),
                  //       ),
                  //     ),
                  //
                  //
                  //     Container(
                  //       width: width(240),
                  //       alignment: Alignment.center,
                  //       padding: EdgeInsets.all(width(5)),
                  //       decoration: BoxDecoration(
                  //         gradient: LinearGradient(
                  //           colors: [
                  //             Colors.transparent,
                  //             Color(0xFFd16519),
                  //             Color(0xFFd16519),
                  //             Colors.transparent
                  //           ]
                  //         )
                  //       ),
                  //       child: RichText(
                  //         textAlign: TextAlign.center,
                  //         text: TextSpan(
                  //           style: TextStyle(fontSize: sp(14),),
                  //           text: "注册即送"+
                  //               " \n",
                  //           children: [
                  //             TextSpan(
                  //               text: "价值178元钻石礼包"
                  //             )
                  //           ]
                  //         ),
                  //       ),
                  //     ),
                  //     Positioned(
                  //       bottom: 0,
                  //       left: 0,
                  //       right: 0,
                  //       child:GestureDetector(
                  //         child: Container(
                  //           alignment: Alignment.center,
                  //           child: SPClassEncryptImage.asset(
                  //             SPClassImageUtil.spFunGetImagePath("ic_btn_fuli"),
                  //             width: height(147),
                  //           ),
                  //         ),
                  //         onTap: (){
                  //           Navigator.of(context).pop();
                  //           SPClassNavigatorUtils.spFunPushRoute(context, SPClassNewUserWalFarePage());
                  //         },
                  //       ) ,
                  //     )
                  //   ],
                  // ),
                  //
                  Stack(
                    children: <Widget>[
                      Image.asset(
                        SPClassImageUtil.spFunGetImagePath("ic_fuli_bg"),
                        width: width(288),
                      ),
                      Positioned(
                        top: width(120),
                        left: 0,
                        right: 0,
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: width(10)),
                          child: GridView.count(
                            shrinkWrap: true,
                            crossAxisCount: 2,
                            mainAxisSpacing: height(5),
                            crossAxisSpacing: width(10),
                            childAspectRatio: width(130)/width(70),
                            children: widget.list!.map((e){
                              return itemWidget(e);
                            }).toList(),
                          ),
                        ),

                      ),
                      Positioned(
                        bottom: width(23),
                        left: 0,
                        right: 0,
                        child: GestureDetector(
                          onTap: (){
                            Navigator.of(context).pop();
                            SPClassNavigatorUtils.spFunPushRoute(context, SPClassRechargeDiamondPage());
                          },
                          child: Container(
                            margin: EdgeInsets.symmetric(horizontal: width(59)),
                            color: Colors.white.withOpacity(0.2),
                            height: width(35),
                            alignment: Alignment.center,
                            child: Text('立即充值',style: TextStyle(color: Colors.white,fontSize: sp(14)),),
                          ),
                        ),
                      )
                    ],
                  ),
                  SizedBox(height: width(15),),
                  GestureDetector(
                    child: Container(
                      padding: EdgeInsets.all(width(5)),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(50),
                          border:Border.all(color: Colors.white,width: 2)
                      ),
                      child: Icon(Icons.close,color: Colors.white,size: 20,),
                    ),
                    onTap: (){
                      Navigator.of(context).pop();
                      if(widget.callback!=null){
                        widget.callback!();
                      }
                    },
                  )
                ],
              ),
            ),
          ],
        ),
      ),
      onWillPop:() async{
        return false;
      },
    );
  }


  Widget itemWidget(Map data){
    return Container(
      width: width(130),
      height: width(70),
      decoration: BoxDecoration(
          image: DecorationImage(
            image:AssetImage(SPClassImageUtil.spFunGetImagePath("ic_fuli_money_bg"),),
          )
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(2),
                  color:Color(0xFFFFB44D),
                ),
                child: Text('赠\n送',style: TextStyle(color: MyColors.white,fontSize: sp(9),height: 1.2)),
                padding: EdgeInsets.symmetric(vertical: width(1),horizontal: width(1)),
              ),
              SizedBox(width: width(2),),
              Text('${int.parse(data['diamond'].toString())-int.parse(data['money'].toString())}',style: TextStyle(color: MyColors.main1,fontSize: sp(27),fontWeight: FontWeight.bold)),
              SizedBox(width: width(2),),
              Container(
                width: width(15),
                height: width(15),
                margin: EdgeInsets.only(top: width(8)),
                alignment: Alignment.center,
                padding: EdgeInsets.all(1),
                decoration: BoxDecoration(
                  color: MyColors.main1,
                  borderRadius: BorderRadius.circular(150),
                ),
                child: Text('钻',style: TextStyle(color: MyColors.white,fontSize: sp(10),height: 1.2)),
              ),
            ],
          ),
          Text('${data['isFirst']?'首充':'充值'}${data['money']}元',style: TextStyle(color: MyColors.grey_99,fontSize: sp(12),height: 0.8),),
        ],
      ),
    );
  }

}